/**
 * Created by csy on 17/4/25.
 */
var schedule = require('node-schedule');
var fs = require('fs');
var path = require('path');
var mkdirs = require('./mkdir');


function scheduleRecurrenceRule() {

    var rule = new schedule.RecurrenceRule();
    // rule.dayOfWeek = 2;
    // rule.month = 3;
    // rule.dayOfMonth = 1;
    // rule.hour = 1;
    // rule.minute = 0;
    rule.second = 0;

    schedule.scheduleJob(rule, function() {
        //console.log('scheduleRecurrenceRule:' + new Date());
        let date = new Date();
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let day = date.getDate();
        let hours = date.getHours();
        let minutes = date.getMinutes();
        let second = date.getSeconds();
        let url = process.cwd() + '/upload/' + year + '/' + month + '/' + day;
        mkdirs(url, function(){
             console.log("创建成功")
        })
    });

   
    // fs.mkdir(url, function(err){
    //     if(err){
    //         console.log("mkdirErr: ", err);
    //     }
    // });
    
    // fs.stat('./public',function(err){
    //     console.log(err)        
    // })
    // fs.mkdir("./upload", function(err){
    //     console.log("mkdirErr: ", err);
    // });

}

module.exports = scheduleRecurrenceRule;